{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-12-01\n",
      "2024\n",
      "12\n",
      "1\n",
      "6\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "from datetime import date\n",
    "\n",
    "n = date(2024,12,1)\n",
    "\n",
    "print(n)\n",
    "\n",
    "print(n.year)\n",
    "print(n.month)\n",
    "print(n.day)\n",
    "\n",
    "print(n.weekday()) # 0 星期1 ~ 6 星期日\n",
    "print(n.isoweekday()) # 周几  1~7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:张三,票价0\n"
     ]
    }
   ],
   "source": [
    "# 游园门票的基类\n",
    "class Ticket:\n",
    "\n",
    "    def __init__(self,name,id,date):\n",
    "        self.name = name\n",
    "        self.id = id\n",
    "        self.date = date\n",
    "        self.price = 0\n",
    "\n",
    "    def show(self):\n",
    "        print(\"姓名:{},票价{}\".format(self.name,self.price))\n",
    "\n",
    "t1 = Ticket('张三','1234',date(2024,12,2))\n",
    "t1.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:李四,票价80.0\n",
      "姓名:李四,票价100\n"
     ]
    }
   ],
   "source": [
    "class Adult(Ticket):\n",
    "    # 类属性\n",
    "    price = 100\n",
    "\n",
    "    def __init__(self, name, id, date):\n",
    "        super().__init__(name, id, date)\n",
    "\n",
    "    def show(self):\n",
    "        self.price = Adult.price\n",
    "        n = self.date.isoweekday()\n",
    "        if n<6:\n",
    "            self.price *= 0.8\n",
    "        print(\"姓名:{},票价{}\".format(self.name,self.price))\n",
    "\n",
    "t2 = Adult('李四','123123123',date(2024,12,2))\n",
    "t2.show()\n",
    "t3 = Adult('李四','123123123',date(2024,12,1))\n",
    "t3.show()\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:王五,票价40.0\n",
      "姓名:王五,票价50.0\n",
      "王五一家,总票价200.0\n"
     ]
    }
   ],
   "source": [
    "class Child(Ticket):\n",
    "    price = Adult.price*0.5\n",
    "\n",
    "    def __init__(self, name, id, date):\n",
    "        super().__init__(name, id, date)\n",
    "\n",
    "    def show(self):\n",
    "        self.price = Child.price\n",
    "        n = self.date.isoweekday()\n",
    "        if n<6:\n",
    "            self.price *= 0.8\n",
    "        print(\"姓名:{},票价{}\".format(self.name,self.price)) \n",
    "\n",
    "t4 = Child('王五','123123123123',date(2024,12,2))               \n",
    "t4.show()\n",
    "t5 = Child('王五','123123123123',date(2024,12,1))               \n",
    "t5.show()\n",
    "\n",
    "class Family(Ticket):\n",
    "    def __init__(self, name, id, date,aQty,cQty):\n",
    "        super().__init__(name, id, date)    \n",
    "        self.aQty = aQty\n",
    "        self.cQty = cQty\n",
    "\n",
    "    def show(self):\n",
    "        self.price = (Adult.price*self.aQty + Child.price*self.cQty)*0.8\n",
    "        if self.date.isoweekday()<6:\n",
    "            self.price *= 0.8\n",
    "        print(\"{}一家,总票价{}\".format(self.name,self.price)) \n",
    "\n",
    "t6 = Family('王五','123123123123',date(2024,12,1),2,1)    \n",
    "t6.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
